/// 
/// MaDAson - Toolkit for Model Driven Software Development
/// 
/// Copyright [2006] Marcus Lankenau
/// 
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///  
///     http://www.apache.org/licenses/LICENSE-2.0
///  
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
/// 

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Madason.MetaModel.Transformation
{
	/// <summary>
	/// Parser for Transformation-File
	/// </summary>
	internal class RuleParser
	{
		protected RuleParser() { }

		public static RuleList Load(XmlReader reader)
		{
			RuleList ruleList = new RuleList();

			while (reader.Read())
			{
				if (reader.NodeType == XmlNodeType.Element)
				{
					if (reader.LocalName == "rule")
					{
						Rule rule = new Rule();

						string scopeName = reader.GetAttribute("scope");
						if (scopeName == "Class") rule.Scope = RuleScope.Class;
						else if (scopeName == "Namespace") rule.Scope = RuleScope.Namespace;
						else if (scopeName == "Attribute") rule.Scope = RuleScope.Attribute;
						else if (scopeName == "Operation") rule.Scope = RuleScope.Operation;
						else if (scopeName == "Association") rule.Scope = RuleScope.Association;
						else if (scopeName == "State") rule.Scope = RuleScope.State;
						else throw new ArgumentException("Unknown Rule Scope '" + scopeName + "'");

						rule.Stereotype = reader.GetAttribute("stereotype");
						rule.ParentStereotype = reader.GetAttribute("parentStereotype");
						rule.Target = reader.GetAttribute("target");
						ruleList.Add(rule);
					}
				}
			}

			return ruleList;
		}
	}
}
